﻿using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Mars.Got.SpriteAnim
{
    public class CreatorVisitor : AnimSpriteCreator
    {
        private int m_visitKey = 0;

        public CreatorVisitor(Interface_AnimSpriteSupportTemplate interface_direct, GameObject go, string altasName, Material m_material, int initialCount, int visitKey, BaseSpriteCache spriteCache)
        : base(interface_direct, go, altasName, m_material, initialCount, spriteCache)
        {
            m_visitKey = visitKey;
            SetVisitKey(visitKey);
        }

        public void Dispose_Visit()
        {
            Dispose();
        }

        public bool CheckVisitAuthority(int visitKey)
        {
            if (m_visitKey == visitKey)
            {
                return true;
            }
            else
            {
                if (Debug.unityLogger.logEnabled)
                {
                    Debug.LogError("非法VIsitor！！！！！");
                }
            }
            return false;
        }

        public void SetPropertyBlock_Visit(MaterialPropertyBlock block, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                SetPropertyBlock(block);
            }
        }

        public void GetPropertyBlock_Visit(MaterialPropertyBlock block, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                GetPropertyBlock(block);
            }
        }

        public void SetRendererPriority(int priority, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                SetRendererPriority(priority);
            }
        }
        public void SetTextureSheetAnimation_Visit(int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                SetTextureSheetAnimation(true);
            }
        }

        // public AnimSprite AddParticleFromUnitPars_Visit(string spriteName, int visitKey)
        // {
        //     if (CheckVisitAuthority(visitKey))
        //     {
        //         return AddParticleFromUnitPars(spriteName);
        //     }
        //
        //     return null;
        // }

        public AnimSprite[] AddParticleFromUnitPars_Visit(string spriteName, int count, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                return AddParticleFromUnitPars(count, spriteName);
            }
            return null;
        }

        public AnimSprite AddSingleParticleFromUnitPars_Visit(string spriteName, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                return AddParticleFromUnitPars(spriteName);
            }

            return null;
        }

        public void ForceRemoveParticle_Visit(List<AnimSprite> sprites, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                ForceRemoveParticle(sprites);
            }
        }

        public int ForceRemoveParticle_Visit(AnimSprite sprite, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                return ForceRemoveParticle(sprite);
            }
            return -1;
        }
        

        public void SetRanderPriority_Visit(float priority, int visitKey)
        {
            if (CheckVisitAuthority(visitKey))
            {
                SetRanderPriority(priority);
            }
        }
        
        public void CompleteJob_Visit(int visitKey)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("SpriteParticle.RefreshLifeTime_Visit");
            if (CheckVisitAuthority(visitKey))
            {
                CompleteJob();
            }
            //UnityEngine.Profiling.Profiler.EndSample();
        }
    }
}
